package com.f21.f21assessoria.converter;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import org.springframework.stereotype.Component;

@FacesConverter(value = "ConverterPorcentagem")
public class ConverterPorcentagem implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		
		//DecimalFormat formatador = (DecimalFormat) NumberFormat.getPercentInstance();
		double d = Double.parseDouble(value);
		return d;
		
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		
		DecimalFormat formatador = (DecimalFormat) NumberFormat.getPercentInstance();

				return formatador.format(value);
	}

}
